package main

import (
	"fmt"
	"sync"
)

func main() {
	ch := make(chan int, 10)
	wg := sync.WaitGroup{}
	wg.Add(10)
	for i := 0; i < 10; i++ {
		go func(j int) {
			defer wg.Done()
			fmt.Println("j =", j)
			ch <- j
		}(i)
	}
	wg.Wait()
	// 方式一
	/*close(ch)
	for v := range ch {
		fmt.Println("data = ", v)
	}*/

	// 方式二
	/*for i := 0; i < 10; i++ {
		data := <- ch
		fmt.Println("data = ", data)
	}*/
}
